package com.zb.controller;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zb.Service.DepartmentService;
import com.zb.Service.DictionaryService;
import com.zb.Service.TaskService;
import com.zb.Service.UserService;
import com.zb.Service.WorkService;
import com.zb.entity.Work;

@Scope("prototype")
@Component
@RequestMapping("/work")
public class WorkController {
	@Resource
	private WorkService ws;
	
	@Resource
	private UserService us;
	
	@Resource
	private DepartmentService ds;
	
	@Resource
	private DictionaryService dss;
	
	@Resource
	private TaskService ts;
	//添加出差申请
	@RequestMapping(params="op=save")
	public String saveWork(int userid, Integer dicid, int deptid, String starttime,
			String endtime, String content, String wordconten, int usemoney,
			int roleid,ModelMap modelMap) {
		Work work = new Work();
		work.setUser(us.getUserById(userid));
		work.setDictionary(dss.getDictionaryById(dicid));
		work.setDepartment(ds.getDeptById(deptid));
		work.setRole(us.getUserById(roleid));
		work.setStarttime(starttime);
		work.setEndtime(endtime);
		work.setContent(content);
		work.setWordconten(wordconten);
		work.setUsemoney(usemoney);
		ws.saveWork(work);
		modelMap.put("msg", "操作成功！");
		int maxid = ws.getMaxId();
		ts.saveTask(userid, 2, maxid, roleid);
		return "work";
	}
}
